package JUC.CAS;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author CKC
 * @DateTime 2021/3/17 18:38
 * <p>
 * 1.  CAS是什么？====>compareAndSet
 * *        比较并交换       原来的值(真实值)与期望值相等(true)，更新值
 */
public class CASDemo {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(5);
        
        System.out.println(atomicInteger.compareAndSet(5, 2222) + "\t current  data:" + atomicInteger.get());
        System.out.println(atomicInteger.compareAndSet(2222, 3123) + "\t current  data:" + atomicInteger.get());
        atomicInteger.getAndIncrement();
    }
}
